home *** CD-ROM | disk | FTP | other *** search
- /**
- AEFX_Sample.c
-
- Part of the Adobe After Effects 3.1 SDK
- Copyright (c)1993-96, Adobe Systems Inc, All Rights Reserved.
-
- A simple After Effects plug-in with a custom user interface demonstrating
- the use of PF_Cmd_Event.
-
- Revision History
- 1.0, created by dmw
- 1.1, Added call to AEFX_CLR_STRUCT macro to clear out PF_ParamDef, ba, 6 Nov 96
- **/
-
- #include "AEFX_Sample.h"
-
-
- static PF_Err About (
- PF_InData *in_data,
- PF_OutData *out_data,
- PF_ParamDef *params[],
- PF_LayerDef *output )
- {
- PF_SPRINTF(out_data->return_msg,
- "%s, v%d.%d\r%s",
- NAME, MAJOR_VERSION, MINOR_VERSION, DESCRIPTION);
-
- return PF_Err_NONE;
- }
-
-
- static PF_Err GlobalSetup (
- PF_InData *in_data,
- PF_OutData *out_data,
- PF_ParamDef *params[],
- PF_LayerDef *output )
- {
- PF_Err err = PF_Err_NONE;
-
- out_data->out_flags |= PF_OutFlag_USE_OUTPUT_EXTENT | PF_OutFlag_CUSTOM_UI;
-
- out_data->my_version = PF_VERSION(MAJOR_VERSION, MINOR_VERSION,
- BUG_VERSION, STAGE_VERSION, BUILD_VERSION);
-
- return err;
- }
-
-
- static PF_Err ParamsSetup (
- PF_InData *in_data,
- PF_OutData *out_data,
- PF_ParamDef *params[],
- PF_LayerDef *output )
- {
- PF_Err err = PF_Err_NONE;
- PF_ParamDef def;
-
- /* Always clear out the PF_ParamDef structure before adding your parameters,
- * this macro will do that.
- */
- AEFX_CLR_STRUCT(def);
-
- def.param_type = PF_Param_FIX_SLIDER;
- PF_STRCPY(def.name, "Horizontal Radius");
- def.u.fd.value_str[0] = '\0'; def.u.fd.value_desc[0] = '\0';
- def.u.fd.dephault = def.u.fd.value = SAM_RADIUS_DFLT;
- def.u.fd.slider_min = def.u.fd.valid_min = SAM_RADIUS_MIN;
- def.u.fd.valid_max = SAM_RADIUS_BIG_MAX;
- def.u.fd.slider_max = SAM_RADIUS_MAX;
- def.u.fd.precision = 1;
- if (err = PF_ADD_PARAM(in_data, -1, &def)) return err;
-
- // AEFX_CLR_STRUCT(def);
-
- def.param_type = PF_Param_FIX_SLIDER;
- PF_STRCPY(def.name, "Vertical Radius");
- def.u.fd.value_str[0] = '\0'; def.u.fd.value_desc[0] = '\0';
- def.u.fd.dephault = def.u.fd.value = SAM_RADIUS_DFLT;
- def.u.fd.slider_min = def.u.fd.valid_min = SAM_RADIUS_MIN;
- def.u.fd.valid_max = SAM_RADIUS_BIG_MAX;
- def.u.fd.slider_max = SAM_RADIUS_MAX;
- def.u.fd.precision = 1;
- if (err = PF_ADD_PARAM(in_data, -1, &def)) return err;
-
- // AEFX_CLR_STRUCT(def);
-
- def.param_type = PF_Param_POINT;
- PF_STRCPY(def.name, "Center");
- def.u.td.x_dephault = def.u.td.x_value = SAM_PTX_DFLT;
- def.u.td.y_dephault = def.u.td.y_value = SAM_PTY_DFLT;
- def.u.td.restrict_bounds = FALSE;
- err = PF_ADD_PARAM(in_data, -1, &def);
-
- if (!err) {
- PF_CustomUIInfo ci;
-
- ci.events = PF_CustomEFlag_LAYER | PF_CustomEFlag_COMP;
-
- ci.comp_ui_width = ci.comp_ui_height = 0;
- ci.comp_ui_alignment = PF_UIAlignment_NONE;
-
- ci.layer_ui_width = ci.layer_ui_height = 0;
- ci.layer_ui_alignment = PF_UIAlignment_NONE;
-
- ci.preview_ui_width = ci.preview_ui_height = 0;
- ci.layer_ui_alignment = PF_UIAlignment_NONE;
-
- err = (*(in_data->inter.register_ui))(in_data->effect_ref, &ci);
- }
-
- out_data->num_params = SAM_NUM_PARAMS;
-
- return err;
- }
-
-
- static PF_Err Render (
- PF_InData *in_data,
- PF_OutData *out_data,
- PF_ParamDef *params[],
- PF_LayerDef *output )
- {
- register long x, y;
- long w = output->width,
- h = output->height;
- long gutter = (output->rowbytes / 4) - w;
- PF_Pixel *bop_out = output->data,
- *bop_in = (params[0]->u.ld.data);
-
- PF_Err err = PF_Err_NONE;
- double rad_x, rad_y, y_ratio;
- double center_x, center_y, dist, dx, dy, dy_sqr;
- double rad_x_inv;
- double y_ratio_inv;
-
- double (*sqrt_t)(double) = ((PF_UtilCallbacks *)in_data->utils)->ansi.sqrt;
- double (*sin_t)(double) = ((PF_UtilCallbacks *)in_data->utils)->ansi.sin;
-
- long min_x, max_x, min_y, max_y;
-
-
- min_x = output->extent_hint.left;
- min_y = output->extent_hint.top;
- max_x = output->extent_hint.right;
- max_y = output->extent_hint.bottom;
-
- center_x = FIX_2_FLOAT(params[SAM_PT]->u.td.x_value);
- center_y = FIX_2_FLOAT(params[SAM_PT]->u.td.y_value);
- rad_x = FIX_2_FLOAT(params[SAM_X_RADIUS]->u.fd.value);
- rad_y = FIX_2_FLOAT(params[SAM_Y_RADIUS]->u.fd.value);
- rad_x /= in_data->downsample_x.den;
- rad_y /= in_data->downsample_y.den;
- rad_x *= in_data->downsample_x.num;
- rad_y *= in_data->downsample_y.num;
-
- rad_x_inv = 1.0 / rad_x;
- y_ratio = rad_y * rad_x_inv;
- y_ratio_inv = 1.0 / y_ratio;
-
- if (rad_x == 0 || rad_y == 0)
- return PF_COPY(¶ms[0]->u.ld, output, NULL, NULL);
-
- for (y=0; y<h; y++) {
- dy = (double)y - center_y;
- dy_sqr = (dy * y_ratio_inv); /* convert to be rad_x relative */
- dy_sqr *= dy_sqr;
-
- if (dy > rad_y || dy < -rad_y || y < min_y || y > max_y) {
- for (x = w; x > 0; x--) *bop_out++ = *bop_in++;
-
- } else for (x = 0; x < w; x++) {
- dx = (double)x - center_x;
-
- if (dx > rad_x || dx < -rad_x || x < min_x || x > max_x) {
- *bop_out++ = *bop_in++;
- continue;
- }
-
- dist = sqrt_t(dx * dx + dy_sqr);
- if (dist == 0 || dist >= rad_x) {
- *bop_out++ = *bop_in++;
- continue;
- } else {
- bop_out->red = bop_out->alpha = 255;
- bop_out->blue = bop_out->green = 0;
-
- }
-
- bop_in++; bop_out++;
- }
- bop_in += gutter;
- bop_out += gutter;
-
- if (((y&1) != 0) && /* only do alternating scanlines */
- (err = PF_PROGRESS(in_data, y+1, h)))
- goto bail;
- }
-
- bail:
- return err;
- }
-
-
- PF_Err main (
-
- PF_Cmd cmd,
- PF_InData *in_data,
- PF_OutData *out_data,
- PF_ParamDef *params[],
- PF_LayerDef *output,
- void *extra )
- {
- PF_Err err = PF_Err_NONE;
- SAM_DECLARE_A4
-
- SAM_SET_A4
-
- switch (cmd) {
- case PF_Cmd_ABOUT:
- err = About(in_data,out_data,params,output);
- break;
- case PF_Cmd_GLOBAL_SETUP:
- err = GlobalSetup(in_data,out_data,params,output);
- break;
- case PF_Cmd_PARAMS_SETUP:
- err = ParamsSetup(in_data,out_data,params,output);
- break;
- case PF_Cmd_RENDER:
- err = Render(in_data,out_data,params,output);
- break;
- case PF_Cmd_EVENT:
- err = HandleEvent(in_data,out_data,params,output,extra);
- break;
- }
-
- SAM_RESTORE_A4
-
- return err;
- }
-